<?php
namespace app\api\controller;
use think\Db;
class Article
{
  //轮播图文章
  public function carousel()
  {
    $carouselConfig = Db::name("system")->where("config","carousel")->value("value");
    $carouselArticle = Db::name("article")->field("article_id,title,img")->where("article_id","in", $carouselConfig)->select();

    return json($carouselArticle);
  }
  //置顶文章
  public function topArticle()
  {
    $topArticleConfig = Db::name("config")->where("config","topArticle")->value("value");
    $topArticleArticle = Db::name("article")->field("article_id,title,img")->where("article_id","in", $topArticleConfig)->select();

    return json($topArticleArticle);
  }
    //最新文章
  public function newList()
  {   
    $newList = Db::name('article')->field("content",true)->order("article_id desc")->paginate(10);    
    return json($newList);
  }
  //分类列表
  public function category()
  {
    $category= Db::name("category")->order( 'id desc')->select();   
    return json($category);
  }

  //文章详情
  public function detail()
  {
    $id = input('id');
    $article = Db::name('article')->alias('a')->join('user u','a.uid = u.uid')->join('category c','a.category_id = c.id')->where("article_id",$id)->find();
    return json($article);
  }
  //分类文章
  public function cateArticle()
  {  
    $id = input('cateId');
    $newList = Db::name('article')->order("article_id desc")->where("category_id",$id)->paginate(10);    
    return json($newList);
  }
 
  //分类列表
  public function categoryList()
  {
    $list = Db::name("category")->field("id,category_name")->select();
    return json($list);
  }

}